"""
套接字编程 - TCP客户端
"""
from socket import socket

client = socket()
client.connect(('127.0.0.1', 6789))
file_size = int(client.recv(4096).decode())
with open('new_file.jpg', 'wb') as file:
    data = client.recv(4096)
    total = 0
    while data:
        file.write(data)
        total += len(data)
        if total == file_size:
            break
        data = client.recv(4096)
client.close()
